﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Base.cshtml";
}

<input type="hidden" id="selguarcompanyid" />
<input type="hidden" id="edittype" />
<table border="0" width="100%" >  
    <tr style="margin:5px">
        <td>
            <span style="font-size: 14px">关键字:</span>
            <input id="txtKey" name="txtKey"  type="text" class="input-medium search-query" placeholder="公司名称/简介/描述" style="width: 250px;
                background-color: #fff;"/>
            <button class="btn btn-primary btn-small" id="btnSearch">
                查询
            </button>
        </td>
        <td align="right">
            <button id="btnAdd" class="btn btn-primary btn-small" style="margin-right: 20px">
                新增保险公司
            </button>
        </td>
    </tr>
</table>
<table id="guarcompanygrid" class="mmg">
    <tr>
        <th rowspan="" colspan="">
        </th>
    </tr>
</table>
<div id="pg" style="text-align: right;">
</div>

@section tail{
    <script src="/content/plugins/mmgrid/mmGrid.js" type="text/javascript"></script>
    <script src="/content/plugins/mmgrid/mmPaginator.js" type="text/javascript"></script>
    <script type="text/javascript">
        var cols = [
            { title: '公司名称', name: 'CompanyName', width: 100, align: 'center' },
            { title: '公司图标', name: 'Summary', width: 120, align: 'center', renderer: function (val, item, index) {
                var filename = item['LogoImage'];
                var img = "<img alt='" + filename + "' title='" + filename + "' src='" + filename + "' style='width:80px; height:60px;'/>";
                return img;
            }
            },
            { title: '状态', name: 'Status', width: 30, align: 'center', renderer: function (val, item, index) {
                if (val == 0) return '禁用';
                return '正常';
            }
            },
            { title: '创建人', name: 'CreateUser', width: 40, align: 'center' },
            { title: '创建时间', name: 'CreateTime', width: 120, align: 'center' },
            { title: '操作', name: '', width: 250, align: 'center', lockWidth: true, lockDisplay: true, renderer: function (val, item, index) {
                var html = '<button  class="btn btn-info btn-mini" onclick="guarcompanyEdit(\'' + item['ID'] + '\', -1)">详情</button>';
                html += ' <button  class="btn btn-info btn-mini" onclick="guarcompanyEdit(\'' + item['ID'] + '\', 1)">编辑</button>';
                if (item['Status'] == 1) {
                    html += ' <button  class="btn btn-info btn-mini" onclick="changeStatus(\'' + item['ID'] + '\', 0)">禁用</button>';
                }
                else {
                    html += ' <button  class="btn btn-info btn-mini" onclick="changeStatus(\'' + item['ID'] + '\', 1)">启用</button>';
                }
                html += ' <button  class="btn btn-danger btn-mini" onclick="changeStatus(\'' + item['ID'] + '\', -1)">删除</button>';
                return html;
            }
            }
        ];

        var mmg;
        $(function () {
            $("#btnAdd").click(function () {
                location.href = decodeURIComponent("/GuarCompany/GuarCompanyAdd");
            });

            mmg = $('#guarcompanygrid').mmGrid({
                indexCol: true,
                indexColWidth: 25,
                height: $("body", parent.document).height() - 220,
                cols: cols,
                url: "/GuarCompany/GetGuarCompanyListByPage",
                params: { key: $("#txtKey").val() },
                //method: 'get',
                remoteSort: true,
                //items: items,
                //sortName: 'SECUCODE',
                //sortStatus: 'asc',
                multiSelect: false,
                checkCol: false,
                fullWidthRows: true,
                autoLoad: false,
                plugins: [
                        $('#pg').mmPaginator()
                    ]
            });
            mmg.load();
            $("#btnSearch").click(function () {
                search();
            });
        });

        function search() {
            mmg.setParm({ key: $("#txtKey").val() });
            mmg.load({ page: 1 });
        }

        function guarcompanyEdit(guarcompanyid, opertype) {
            location.href = decodeURIComponent("/GuarCompany/GuarCompanyEdit?guarcompanyid=" + guarcompanyid + "&editType=" + opertype);
        }

        // 改变担保公司状态
        function changeStatus(guarcompanyid, destinatstatus) {
            var deststatus;
            if (destinatstatus == 1) {
                deststatus = "启用";
            }
            else if (destinatstatus == 0) {
                deststatus = "禁用";
            }
            else if (destinatstatus == -1) {
                deststatus = "删除";
            }

            bootbox.confirm("<span style='font-size:14px;'><i style='color:green;' class='icon-question-sign bigger-290'></i> &nbsp;&nbsp;确定要" + deststatus + "该记录吗？</span>", '300px', function (confirmed) {
                if (confirmed == true) {
                    $.ajax({
                        url: '/GuarCompany/GuarCompanyStatusChange',
                        data: "guarCompanyId=" + guarcompanyid + "&destinatStatus=" + destinatstatus,
                        type: "post",
                        cache: false,
                        success: function (result) {
                            if (result == "True") {
                                bootbox.alert("<span style='font-size:14px;'><i style='color:green;' class='icon-ok-sign bigger-290'></i>   " + deststatus + "成功</span>", '300px');
                                mmg.load();
                            } else {
                                bootbox.alert("<span style='font-size:14px;'><i style='color:green;' class='icon-remove-sign bigger-290'></i>   " + deststatus + "失败</span>", '300px');

                            }
                        }
                    });
                }
            });
        }

    </script>
}